package com.defangit.production.orm;

import com.defangit.production.bll.ManufactureFormBll;
import com.defangit.production.domain.ManufactureForm;
import laogen.hibernate.CommonFinder;
import laogen.hibernate.CommonService;
import org.hibernate.Criteria;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

public class ManufactureFormService extends CommonService<ManufactureForm> implements ManufactureFormBll {
    public ManufactureForm addForm(String formName) {
        ManufactureForm manufactureForm = new ManufactureForm();
        manufactureForm.setName(formName);
        add(manufactureForm);
        commitSession();
        return manufactureForm;
    }

    @Override
    public ManufactureFormFinder findAll() {
        return new ManufactureFormFinderImp();
    }


    public class ManufactureFormFinderImp extends CommonFinder<ManufactureForm> implements ManufactureFormFinder {

        private DetachedCriteria formCriteria;
        private ManufactureFormFinderImp() {
            this.formCriteria = detachedAll();
        }
        @Override
        public Criteria getCriteria() {
            return this.formCriteria.getExecutableCriteria(getSession());
        }

        @Override
        public DetachedCriteria getDetachedCriteria() {
            return formCriteria;
        }

        public  ManufactureFormFinder formId(Integer formId) {
            if (formId==null) return this;
            this.formCriteria.add(Restrictions.eq("id",formId));
            return this;
        }

        public ManufactureFormFinder formName(String forName) {
            if (forName==null) return this;
            this.formCriteria.add(Restrictions.eq("name",forName));
            return this;
        }

    }

}
